package com.shop2cn.iapi.agentproducts.testcase;

import java.util.ArrayList;
import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.iapi.agentproducts.parameter.AddAgentProductBean;
import com.shop2cn.iapi.agentproducts.parameter.ImportAgentProductBean;
import com.shop2cn.iapi.agentproducts.parameter.ProductDetailsBean;
import com.shop2cn.iapi.agentproducts.parameter.ProductDetailsDto;
import com.shop2cn.iapi.agentproducts.parameter.ProductListDto;
import com.shop2cn.iapi.agentproducts.parameter.SetVipChannelBean;
import com.shop2cn.iapi.agentproducts.service.SetVipChannelCall;
import com.ymatou.iapi.dguser.parameter.UserCreateBean;
import com.ymatou.iapi.godmch.parameter.CreateCodeBean;
import com.ymatou.iapi.godmch.parameter.createmchBean;
import com.ymatou.iapi.godmch.service.CreateCodeCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.AddAgentProductCallService;
import com.ymttest.business.service.DGUserCallService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;

/**
 * 设置vip渠道Test FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_SetVipChannel {
	private static SetVipChannelBean setvipchannelBean;
	private static SetVipChannelCall setvipchannelCall;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("设置vip渠道Test");
	}

	@Before
	public void caseUp() {
		setvipchannelBean = new SetVipChannelBean();
		setvipchannelCall = new SetVipChannelCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(setvipchannelCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_SetVipChannel_001() {
		Logger.start(true, "正确数据，成功");
		try {
			
			//创建渠道商
			CreateCodeBean createAllMsgSellerMch = GodmchManageCallService.CreateAllMsgSellerMch();
			//创建渠道商邀请码
			CreateCodeCall createCodeCall2 = GodmchManageCallService.createCodeCall(createAllMsgSellerMch);
			//创建代理商
			Integer userId_agent = GodmchManageCallService.CreateSellerMch(createCodeCall2.getJsonObject().getAsJsonObject("result").get("code").getAsString());
			int userId_channl=createAllMsgSellerMch.getMchId();
			GodmchManageCallService.SetVip(userId_channl);
			// 给渠道商创建一个商品
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(userId_channl,
					"", true);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			Thread.sleep(5000);
			// 代理商导入
			ImportAgentProductBean initImportAgentProduct = AddAgentProductCallService.initImportAgentProduct(
					userId_agent, "", productId, userId_channl, false);
			String productId1 = AddAgentProductCallService.ImportAgentProduct(initImportAgentProduct);

			List<ProductListDto> getProductLists = AddAgentProductCallService.GetProductLists(userId_agent);
			System.out.println(getProductLists);

			ProductDetailsBean initGetProductDetails = AddAgentProductCallService.initGetProductDetails(userId_channl,
					userId_channl, productId, true);
			ProductDetailsDto selectProductDetails = AddAgentProductCallService
					.GetProductDetailsCall(initGetProductDetails);

			List<String> catalogs = new ArrayList<>();
			selectProductDetails.getCatalogList().forEach(c -> {
				catalogs.add(c.getCatalogId());
			});

			ProductDetailsBean initGetProductDetails1 = AddAgentProductCallService.initGetProductDetails(userId_channl,
					userId_agent, productId, true);
			ProductDetailsDto selectProductDetails1 = AddAgentProductCallService
					.GetProductDetailsCall(initGetProductDetails1);

			List<String> catalogs1 = new ArrayList<>();
			selectProductDetails1.getCatalogList().forEach(c -> {
				catalogs1.add(c.getCatalogId());
			});

			Thread.sleep(5000);
			
			
			setvipchannelCall.setData(setvipchannelBean);
			setvipchannelCall.callService();
			Logger.verifyEquals("200", setvipchannelCall.getString("code"), "验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}